package com.bili.bili_data_api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bili.bili_data_api.dao.mapper.*;
import com.bili.bili_data_api.dao.pojo.*;
import com.bili.bili_data_api.service.CompareService;
import com.bili.bili_data_api.vo.CpFavourVo;
import com.bili.bili_data_api.vo.CpTongVo;
import com.bili.bili_data_api.vo.TypeList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CompareServiceImpl implements CompareService {
    @Autowired
    private GaoxiaoFavourMapper gaoxiaoFavourMapper;
    @Autowired
    private RichangFavourMapper richangFavourMapper;
    @Autowired
    private GaoxiaoViewMapper gaoxiaoViewMapper;
    @Autowired
    private RichangViewMapper richangViewMapper;
    @Autowired
    private GaoxiaoTongjiMapper gaoxiaoTongjiMapper;
    @Autowired
    private RichangTongjiMapper richangTongjiMapper;

    @Override
    public CpFavourVo getFavour() {
        CpFavourVo cpFavourVo = new CpFavourVo();
//        QueryWrapper<GaoxiaoFavour> queryWrapper1 = new QueryWrapper<>();
//        queryWrapper1.orderByAsc("favour");
//        QueryWrapper<RichangFavour> queryWrapper2 = new QueryWrapper<>();
//        queryWrapper2.orderByAsc("favour");
        List<GaoxiaoFavour> gaoxiaoFavours = gaoxiaoFavourMapper.selectList(null);
        List<RichangFavour> richangFavours = richangFavourMapper.selectList(null);
        List<String> authorList = new ArrayList<>();
        List<String> sList = new ArrayList<>();
        List<String> gList = new ArrayList<>();
        for(int i=9;i>=0;i--){
            authorList.add(richangFavours.get(i).getAuthor()+'/'+gaoxiaoFavours.get(i).getAuthor());
            sList.add(richangFavours.get(i).getFavour());
            gList.add(gaoxiaoFavours.get(i).getFavour());
        }
        cpFavourVo.setAuthorList(authorList);
        cpFavourVo.setNumList1(gList);
        cpFavourVo.setNumList2(sList);
        return cpFavourVo;
    }

    @Override
    public CpFavourVo getView() {
        CpFavourVo cpFavourVo = new CpFavourVo();
        List<GaoxiaoView> gaoxiaoViews = gaoxiaoViewMapper.selectList(null);
        List<RichangView> richangViews = richangViewMapper.selectList(null);
        List<String> authorList = new ArrayList<>();
        List<String> sList = new ArrayList<>();
        List<String> gList = new ArrayList<>();
        for(int i=9;i>=0;i--){
            authorList.add(richangViews.get(i).getAuthor()+'/'+gaoxiaoViews.get(i).getAuthor());
            sList.add(richangViews.get(i).getView());
            gList.add(gaoxiaoViews.get(i).getView());
        }
        cpFavourVo.setAuthorList(authorList);
        cpFavourVo.setNumList1(gList);
        cpFavourVo.setNumList2(sList);
        return cpFavourVo;
    }

    @Override
    public CpTongVo getTong() {
        CpTongVo cpTongVo = new CpTongVo();
        List<GaoxiaoTongji> gaoxiaoTongjis = gaoxiaoTongjiMapper.selectList(null);
        List<RichangTongji> richangTongjis = richangTongjiMapper.selectList(null);
        List<TypeList> gList = new ArrayList<>();
        List<TypeList> sList = new ArrayList<>();
        for(int i=0;i<8;i++){
            TypeList sType = new TypeList();
            TypeList gType = new TypeList();
            gType.setName(gaoxiaoTongjis.get(i).getLabel());
            sType.setName(gaoxiaoTongjis.get(i).getLabel());
            gType.setValue(gaoxiaoTongjis.get(i).getNum());
            sType.setValue(richangTongjis.get(i).getNum());
            gList.add(gType);
            sList.add(sType);
        }
        cpTongVo.setNumList1(sList);
        cpTongVo.setNumList2(gList);
        return cpTongVo;
    }
}
